package com.cxz.food.controller;

import com.cxz.food.domain.FoodCart;
import com.cxz.food.domain.Response;
import com.cxz.food.domain.vo.FoodPlaceResVo;
import com.cxz.food.service.impl.FoodCartServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/foodcart")
public class FoodCartController {

    @Autowired
    private FoodCartServiceImpl foodCartService;


    @RequestMapping(value = "/get/{cartCode}",method = RequestMethod.GET,produces = "application/json")
    public Response getFoodsByCartCode(@PathVariable String cartCode){

        List<FoodPlaceResVo> foods = null;
        try {
            foods = foodCartService.getFoodsByCartCode(cartCode);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return  new Response(200,"获取数据成功",foods);
    }


    @RequestMapping(value = "/add",method = RequestMethod.POST,produces = "application/json")
    public Response insertFoodCart(@RequestBody FoodCart foodCart){

        foodCartService.insertFoodCart(foodCart);

        return  new Response(200,"添加成功");
    }



    @RequestMapping(value = "/delete/{cartCode}",method = RequestMethod.POST,produces = "application/json")
    public Response deleteFoodCartByCartCode(@PathVariable String cartCode){

        foodCartService.deleteFoodCartByCartCode(cartCode);

        return  new Response(200,"删除所有菜成功");
    }

}
